package com.ceba.test.modules.email.entity;

import org.apache.commons.lang.StringUtils;

import com.ceba.test.base.enums.PeopleTypeEnum;
/**
 * 邮件关联的人：发送人，收件人
 * @author Administrator
 */
public class EmailRelationPeople {
	private String email;//邮箱地址 必填项
	private String name;//姓名  发件人必须要有姓名
	private String charset;//编码 默认编码UTF-8
	private PeopleTypeEnum peopleTypeEnum;//邮件人员类型 必填项
	public EmailRelationPeople(){
		this.charset="UTF-8";
	}
	
	public EmailRelationPeople(String email,String name,PeopleTypeEnum peopleTypeEnum){
		this.charset="UTF-8";
		this.email=email;
		this.name=name;
		this.peopleTypeEnum=peopleTypeEnum;
	}
	
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCharset() {
		return charset;
	}
	public void setCharset(String charset) {
		this.charset = charset;
	}
	public PeopleTypeEnum getPeopleTypeEnum() {
		return peopleTypeEnum;
	}
	public void setPeopleTypeEnum(PeopleTypeEnum peopleTypeEnum) {
		this.peopleTypeEnum = peopleTypeEnum;
	}
	@Override
	public String toString() {
		return "EmailRelationPeople [email=" + email + ", name=" + name + ", charset=" + charset + ", peopleTypeEnum="
				+ peopleTypeEnum + "]";
	}
	
	public void valid() throws Exception{
		if(peopleTypeEnum == null){
			throw new NullPointerException("peopleTypeEnum:邮件人员类型不能为空");
		}
		
		if(peopleTypeEnum==PeopleTypeEnum.RECIPIENTS){
			if(StringUtils.isEmpty(name)){
				throw new NullPointerException("subject:发件人姓名不能为空");
			}
		}
		
		if(StringUtils.isEmpty(email)){
			throw new NullPointerException(peopleTypeEnum.getExplain()+"subject:邮件地址不能为空");
		}
	}
	
}
